<?php

namespace app\admin\controller;

use app\admin\common\Adminbase;

use app\admin\model\Department as Departmentmodel;
use service\TreeService;
use think\Db;

class Department extends Adminbase
{
    protected $department_model;

    protected function _initialize(){
        parent::_initialize();
        $this->department_model = new Departmentmodel();
    }

    public function index(){
        if($this->request->isAjax()) {
            $param = $this->request->param();//接收参数
            //dump($param);exit;
            /**
             * 返回获取的分页数据
             */
            return $this->department_model->GetDepartmentDataPage($param);
        }
        return $this->fetch();
    }

    public function setfloor(){
        if($this->request->isAjax()) {
            $data = $this->request->param();
            //dump($data);exit;
            if(isset($data['floorinfo'])){
                Db::name("department")->where(['id'=>$data['id']])->update(['floorinfo'=>implode(",",$data['floorinfo'])]);
                $this->success("提交成功");
            }
            else{
                $this->error("请选择电梯楼层");
            }

        }
        $id = $this->request->param("id/d");
        $info = Db::name("department")->where(['department_id'=>$id])->find();
        $info['floorinfo'] = explode(",",$info['floorinfo']);
        $this->assign("info",$info);
        //dump($info);exit;
        return $this->fetch();
    }

}